<template>
  <div>
    <div class="crumbs">
      <router-link to="/certificate/certificate/pass">
        <el-button>审核通过</el-button>
      </router-link>
      <router-link to="/certificate/certificate/wait">
        <el-button>等待审核</el-button>
      </router-link>
      <router-link to="/certificate/certificate/failed">
        <el-button>审核失败</el-button>
      </router-link>
      <router-link to="/certificate/certificate/invalid">
        <el-button type="success">证书作废</el-button>
      </router-link>
    </div>
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="100"></el-table-column>
      <el-table-column prop="name" label="名称" width="400"></el-table-column>
      <el-table-column prop="create_time" label="创建时间"></el-table-column>
      <el-table-column prop="status_text" label="状态" width="150"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="small" type="info" @click="see(scope.$index, scope.row)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        @current-change ="handleCurrentChange"
        layout="total, prev, pager, next"
        :current-page="textData.current_page"
        :page-size="textData.per_page"
        :total="textData.total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
  import {mapState} from 'vuex'

  export default {
    data () {
      return {
      }
    },
    computed: {
      ...mapState({
        tableData: state => state.certificate.certificateList,
        textData: state => state.certificate.pageData
      })
    },
    created () {
      this.certificatelist()
    },
    methods: {
      // 获取证书列表
      async certificatelist () {
        let payload = {
          page: this.textData.current_page,
          listRows: this.textData.per_page,
          status: 3
        }
        await this.$store.dispatch('certificate/certificateList', payload)
      },
      handleCurrentChange (val) {
        this.textData.current_page = val
        this.certificatelist()
      },
      see (index, row) {
        this.$router.push({name: 'CertificateInfo', params: {id: row.id}})
      }
    }
  }
</script>
